Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplified set typing #95

Merged
merged 1 commit into from
Jun 6, 2024
Merged

simplified set typing #95

merged 1 commit into from
Jun 6, 2024

Conversation

kubikowski
Copy link
Owner

The input sets are publicly declared as either Set<T> or ReadonlySet<T>. And in TypeScript, Set extends ReadonlySet. Because it is functionally the same type but with extra properties for mutability.

When this library was initially written, each function exposed a generic S that extended ReadonlySet. This guaranteed that the return type would be the same as the input set types. And, when declared types were added to this library in v1.1.0, that typing paradigm S remained. But for internal use only, as only explicit cases for Set -> Set and ReadonlySet -> ReadonlySet are exposed in the distribution.

Because there are declared types for each function, that generic is no longer internally necessary. Set extends ReadonlySet. So each function can be internally typed with ReadonlySet. And the resultSets no longer need to be cast to S on return.

@kubikowski kubikowski added type: Refactor just cleaning code: TypeScript changes to the typescript project labels Jun 5, 2024
@kubikowski kubikowski added this to the v1.5.8 milestone Jun 5, 2024
@kubikowski kubikowski self-assigned this Jun 5, 2024
@kubikowski kubikowski merged commit 9442e8c into main Jun 6, 2024
4 checks passed
@kubikowski kubikowski deleted the typing branch June 6, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code: TypeScript changes to the typescript project type: Refactor just cleaning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant